/*
 * @Author: your name
 * @Date: 2021-07-17 09:39:56
 * @LastEditTime: 2021-11-02 10:07:25
 * @LastEditors: Mcfly
 * @Description: In User Settings Edit
 * @FilePath: \FTTfly\Ctrl\PID.h
 */
#ifndef __PID_H_
#define __PID_H_

#include "ButterWorth.h"

#define PARAM_ROLL 0
#define PARAM_PITCH 1
#define PARAM_YAW 2

typedef struct
{
    float Kp;
    float Ki;
    float Kd;

    float limitI;
    float integral;
    float lastError;
    float deltaT;
	
	float pOut;
	float iOut;
	float dOut;
    float out;
} PIDctrler;

PIDctrler *initPID(float Kp, float Ki, float Kd, float limitI, float deltaT);
float PIDProcess(PIDctrler *pid, float error);
float PIDProcessWithSelfIntegralErr(PIDctrler *pid, float error, float integral);
float PIDProcessWithSelfIntegralErrAndFilterD(PIDctrler *pid, float error, float integralErr, ButterBufferData *filterBuf, ButterParameter *filterD);
float PIDProcessWithDiffTriErr(PIDctrler *pid, float pErr, float integralErr, float dErr);
void PIDctrler_SetKp(PIDctrler *pid, float Kp);
void PIDctrler_SetKi(PIDctrler *pid, float Ki);
void PIDctrler_SetKd(PIDctrler *pid, float Kd);

#endif
